"""
注册页面测试
"""
import time

from selenium.webdriver.common.by import By
from Utils.Utils import ForumDriver


class Register:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://127.0.0.1:58080/sign-up.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)

    # 注册成功
    def RegisterSucTest(self):
        # 输入用户名
        # time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("a")
        # 输入昵称
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("a")
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        # 确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        # 勾选隐私条款
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # 点击注册
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # time.sleep(2)
        # 获取快照
        ForumDriver.GetScreenShot()
        # 如果注册成功会自动跳转到登录页面
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        ForumDriver.GetScreenShot()

    def RegisterFail(self):
        # 未确认密码检查元素 “请检查确认密码是否存在”
        # self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("heo")
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("heo")
        # self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div")
        # 未填写昵称
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("heo")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div")

# register = Register()
# # register.RegisterSucTest()
# register.RegisterFail()
